package com.songcha.library_business

import android.app.Application
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.songcha.library_business.config.NetworkConfig
import com.songcha.library_business.helper.SmartRefreshHelper
import com.songcha.library_business.provider.IApplicationInitProvider
import com.songcha.library_business.proxy.userinfo.UserInfoManager
import com.songcha.library_common.BuildConfig
import com.songcha.library_common.LibraryCommon
import com.songcha.library_database.LibraryDatabaseApplication


class LibraryBusinessApplication {
    companion object{
        private lateinit var mContext: Context
        private var mIsInitApp = false

        @JvmStatic
        fun getContext():Context{
            return mContext
        }

        @JvmStatic
        fun setIsInitApp(){
            mIsInitApp = true
        }

        @JvmStatic
        fun isInitApp():Boolean{
            return mIsInitApp
        }

        init {
           SmartRefreshHelper.init()
        }

        @JvmStatic
        fun init(application: Application){
            mContext = application

            //LibraryCommon.init(mContext,BuildConfig.DEBUG)
            //ModuleReaderApplication.init(mContext)
            //LibraryDatabaseSakuraApplication.init(mContext)
            LibraryCommon.init(application)

            if(com.songcha.library_business.BuildConfig.DEBUG){
                ARouter.openLog()
                ARouter.openDebug()
            }
            ARouter.init(application)

            //database init
            LibraryDatabaseApplication.init(application)

            //module init
            ARouter.getInstance().build("/main/AppInitImpl").navigation()?.let {
                it as IApplicationInitProvider
                it.initApplication(application)
            }

            ARouter.getInstance().build("/splash/AppInitImpl").navigation()?.let {
                it as IApplicationInitProvider
                it.initApplication(application)
            }


            //release force modify to release domain
            if(!BuildConfig.DEBUG && NetworkConfig.IS_PACK_RELEASE) {
                NetworkConfig.IS_RELEASE = true
            }

            UserInfoManager.init()


            //WxHelper.initWxApi(application,application.resources.getString(R.string.wx_appid))

        }
    }

}